<template>
  <div class="app-container">
    <el-row :gutter="20">
      <splitpanes :horizontal="appStore.device === 'mobile'" class="default-theme">
        <!--用户数据-->
        <pane size="84">
          <el-col>
<!--            <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
              <el-form-item label="门店名称" prop="storeName">
                <el-input v-model="queryParams.storeName" placeholder="请输入门店名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item label="店长名称" prop="managerName">
                <el-input v-model="queryParams.managerName" placeholder="请输入店长名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>

              <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>

            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="warning" plain icon="Download" @click="handleExport">导出</el-button>
              </el-col>
            </el-row>-->

            <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="50" align="center" />
              <el-table-column label="门店名称" align="center" key="storeName" prop="storeName" />
              <el-table-column label="门店地址" align="center" key="storeAddress" prop="storeAddress" />
              <el-table-column label="店长名称" align="center" key="managerName" prop="managerName" />
              <el-table-column label="本月收款总额" align="center" key="dateTotalAmount" prop="dateTotalAmount" />
              <el-table-column label="本月付款总额" align="center" key="dateTotalPayAmount" prop="dateTotalPayAmount" />
              <el-table-column label="本月现金余额" align="center" key="dateMoneyAmount" prop="dateMoneyAmount" />
              <el-table-column label="本月现金累计总额" align="center" key="dateMoneyTotalAmount" prop="dateMoneyTotalAmount" />
              <el-table-column label="本月中介费收入" align="center" key="dateZjTotalAmount" prop="dateZjTotalAmount" />
              <el-table-column label="本月中介费现金" align="center" key="dateZjMoneyAmount" prop="dateZjMoneyAmount" />
              <el-table-column label="本月中介费刷卡" align="center" key="dateZjPostAmount" prop="dateZjPostAmount" />
              <el-table-column label="本月中介费微信" align="center" key="dateZjWechatAmount" prop="dateZjWechatAmount" />
              <el-table-column label="本月中介费支付宝" align="center" key="dateZjAlipayAmount" prop="dateZjAlipayAmount" />
              <el-table-column label="本月中介费总金额" align="center" key="dateZjTotalAmountMonth" prop="dateZjTotalAmountMonth" />
              <el-table-column label="创建时间" align="center" key="createTime" prop="createTime" />
              <el-table-column label="更新时间" align="center" key="updateTime" prop="updateTime" />
            </el-table>
            <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
          </el-col>
        </pane>
      </splitpanes>
    </el-row>
  </div>
</template>

<script setup name="User">
import useAppStore from '@/store/modules/app'
import { listMonth, } from "@/api/storeTable/storeTable.js"
import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css"

const router = useRouter()
const appStore = useAppStore()
const { proxy } = getCurrentInstance()
const userList = ref([])
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const names = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const dateRange = ref([])

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    storeName: undefined,
    managerName: undefined,
  }
})

const { queryParams, form } = toRefs(data)

/** 查询用户列表 */
function getList() {
  loading.value = true
  listMonth(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
    loading.value = false
    userList.value = res.rows
    total.value = res.total
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = []
  proxy.resetForm("queryRef")
  handleQuery()
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download("system/customer/export", {
    ...queryParams.value,
  },`user_${new Date().getTime()}.xlsx`)
}

/** 选择条数  */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  names.value = selection.map(item => item.name)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加用户"
}



/** 重置操作表单 */
function reset() {
  form.value = {
    managerId: undefined,
    name: undefined,
    status: "",
    address: undefined,
    managerPhone: undefined,
    mangerCard: undefined,
    mangerSex: undefined,
    roleId: undefined,
    remark: undefined,
  }
  proxy.resetForm("userRef")
}

onMounted(() => {
  getList()
})
</script>